package com.fosss.search;

/**
 * 线性查找，找一个数
 */
public class LinearSearch {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,9,55};
        int result = linearSearch(arr, 5);
        if(result==-1){
            System.out.println("没有找到");
        }else {
            System.out.println("下标为："+result);
        }

    }

    public static int linearSearch(int[] arr,int value){
        for(int i=0;i<arr.length;i++){
            if(arr[i]==value){
                return i;
            }
        }
        return -1;
    }
}
